<!DOCTYPE HTML>
<html>
<head>
<title>Test declared after harness completion</title>
</head>
<body>
<div id="log"></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<p>This test simulates an automated test running scenario, where the test
results emitted by testharness.js may be interpreted after some delay. It is
intended to demonstrate that in such cases, any additional tests which are
executed during that delay are included in the dataset.</p>

<p>Although these "late tests" are likely an indication of a mistake in test
design, they are also recorded. Previously, "late tests" were ignored.
This test changed to assert "late tests" were no longer ignored after
https://github.com/web-platform-tests/wpt/pull/38806 was introduced.</p>
<script>
async_test(function(t) {
    var source = [
        "<div id='log'></div>",
        "<script src='/resources/testharness.js'></" + "script>",
        "<script src='/resources/testharnessreport.js'></" + "script>",
        "<script>",
        "parent.childReady(window);",
        "setup({ explicit_done: true });",
        "test(function() {}, 'acceptable test');",
        "onload = function() {",
        "  done();",
        "  test(function() {}, 'test registered in onload handler');",
        "};",
        "</" + "script>"
    ].join("\n");
    var iframe = document.createElement("iframe");

    document.body.appendChild(iframe);
    window.childReady = t.step_func(function(childWindow) {
        childWindow.add_completion_callback(t.step_func(function(tests, status) {
            t.step_timeout(t.step_func(function() {
                assert_equals(tests.length, 2);
                assert_equals(tests[0].name, "acceptable test");
                assert_equals(tests[1].name, "test registered in onload handler");
                assert_equals(status.status, status.OK);
                t.done();
            }), 0);
        }));
    });

    iframe.contentDocument.open();
    iframe.contentDocument.write(source);
    iframe.contentDocument.close();
});
</script>
</body>
</html>
